package com.aps.algorithm.utils;

import com.aps.algorithm.heuristic.genetic.dto.ApsOperationDto;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import org.springframework.beans.BeanUtils;
import org.springframework.util.ClassUtils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @Author nbZhuozh
 * @Date 2025-09-09  10:58
 **/
public class AlgorithmUtils {

    /**
     * 将数据 全排列
     * @param datas
     * @return
     * @param <T>
     */
    public static <T> List<List<T>>  getPermutationsList(List<T> datas){
        List<List<T>> result = new ArrayList<>();
        getPermutations(datas, 0, result);
        return result;
    }
    public static <T> void getPermutations(List<T> datas , int start, List<List<T>> result){
        if (start == datas.size()) {
            result.add(new ArrayList<>(datas));
            return;
        }
        for (int i = start; i < datas.size(); i++) {
            // 交换元素
            Collections.swap(datas, start, i);
            // 递归生成剩余排列
            getPermutations(datas, start + 1, result);
            // 恢复原状
            Collections.swap(datas, start, i);
        }
    }


}
